package oop;

public class TestStatic {
    static{
        System.out.println("------我是静态代码块-----");

    }

    {
        System.out.println("===我是代码块=====");
    }

    public static void main(String[] args) {
        System.out.println(TestStatic.b);//0
        TestStatic ts = new TestStatic();
        ts.a = 5;
        ts.b = 7;
        System.out.println("a="+ts.a);//5
        System.out.println("b="+ts.b);//7
        TestStatic ts2 = new TestStatic();
        System.out.println(ts2.a);//0
        ts2.a= 8;
        System.out.println("ts2.b="+ts2.b);//7
        System.out.println(ts2.a);
        TestStatic.b = 100;
        System.out.println(ts.b+","+ts2.b+","+TestStatic.b);//100
        String s = ts.checkCode(4);
        System.out.println(s);
        System.out.println(ts2.checkCode(5));
        System.out.println(TestStatic.checkCode(6));
    }


    int a;
    static int b;

    public static String checkCode(int n){
        String code="";
        String str = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        for(int i=0;i<n;i++){
            int index = (int)(Math.random()*str.length());
            char c = str.charAt(index);
            code += c;
        }
        return code;
    }




}
